using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using Microsoft.EntityFrameworkCore;
using System.ComponentModel.DataAnnotations;
using HengTong.Model.Db.System;


namespace HengTong.ViewModel._Admin.SysNotificationCategoryVms
{
    public partial class SysNotificationCategoryListVm : BasePagedListVM<SysNotificationCategoryView, SysNotificationCategorySearcher>
    {

        protected override IEnumerable<IGridColumn<SysNotificationCategoryView>> InitGridHeader()
        {
            return new List<GridColumn<SysNotificationCategoryView>>{
                this.MakeGridHeader(x => x.Name),
                this.MakeGridHeader(x => x.Code),
                this.MakeGridHeader(x => x.Description),
                this.MakeGridHeader(x => x.Icon),
                this.MakeGridHeader(x => x.EnableInternalMessage),
                this.MakeGridHeader(x => x.EnableSms),
                this.MakeGridHeader(x => x.EnableEmail),
                this.MakeGridHeader(x => x.EnableAppPush),
                this.MakeGridHeader(x => x.EnableWechatPush),
                this.MakeGridHeader(x => x.EnableDingTalkPush),
                this.MakeGridHeader(x => x.DefaultPriority),
                this.MakeGridHeader(x => x.IsEnabled),
                this.MakeGridHeader(x => x.SortOrder),
                this.MakeGridHeader(x => x.ParentName),
                this.MakeGridHeaderAction(width: 200)
            };
        }

        public override IOrderedQueryable<SysNotificationCategoryView> GetSearchQuery()
        {
            var query = DC.Set<SysNotificationCategory>()
                .CheckEqual(Searcher.EnableInternalMessage, x=>x.EnableInternalMessage)
                .CheckEqual(Searcher.EnableSms, x=>x.EnableSms)
                .CheckEqual(Searcher.EnableEmail, x=>x.EnableEmail)
                .CheckEqual(Searcher.EnableAppPush, x=>x.EnableAppPush)
                .CheckEqual(Searcher.EnableWechatPush, x=>x.EnableWechatPush)
                .CheckEqual(Searcher.EnableDingTalkPush, x=>x.EnableDingTalkPush)
                .CheckEqual(Searcher.IsEnabled, x=>x.IsEnabled)
                .Select(x => new SysNotificationCategoryView
                {
				    ID = x.ID,
                    Name = x.Name,
                    Code = x.Code,
                    Description = x.Description,
                    Icon = x.Icon,
                    EnableInternalMessage = x.EnableInternalMessage,
                    EnableSms = x.EnableSms,
                    EnableEmail = x.EnableEmail,
                    EnableAppPush = x.EnableAppPush,
                    EnableWechatPush = x.EnableWechatPush,
                    EnableDingTalkPush = x.EnableDingTalkPush,
                    DefaultPriority = x.DefaultPriority,
                    IsEnabled = x.IsEnabled,
                    SortOrder = x.SortOrder,
                    ParentName = x.Parent.Name,
                })
                .OrderBy(x => x.ID);
            return query;
        }

    }

    public class SysNotificationCategoryView : SysNotificationCategory{
        [Display(Name = "分类名称")]
        public String ParentName { get; set; }

    }
}
